/*
*类描述：新增noticejs
*开发者：sjc
*创建时间：2018-8-19 14:42:36
*/
//公告id
var ntId;
$(function () {
    sessionStorage.removeItem("memberList");
    //select初始化

    // if('0'==type){
    //     set0();
    // }else{
    //     set1(type);
    // }

    $("input[name=acceptObj]").click(function(){
        ntId = $("#noticeId").val();
        if(ntId == null || ntId == "" || ntId == "undefined"){
            layer.msg('请保存公告标题和类型',{icon:3})
            return false;
        }
        var accept = $(this).val();
        if(accept == "2"){
            $.ajax({
                url:application.contextPath+"/notice/showMemberPage?noticeId="+ntId,
                success:function(res){
                    layer.open({
                        type:1,
                        title:'选择需要发送的人员',
                        content:res,
                        maxmin:true,//最大，最小开关
                        shade:0.5,//遮盖层模糊度
                        anim:1,//打开跟关闭动画
                        scrollbar:true,//是否设置滚轮
                        area:["1080px","510px"]
                    })
                }
            })
        }
    });

    $("#case").upload(
        function(_this,data){
            layer.msg("图片链接："+data,{time: 5000},function(){
                //console.log(222);
                //layer.close(index)
            });
        }
    )

    tinymce.init({convert_urls: false,
        selector: '.tinymce',
        height: 300,
        plugins: [
            'advlist autolink lists link image charmap print preview anchor',
            'searchreplace visualblocks code fullscreen',
            'insertdatetime media table contextmenu paste code'
        ],
        toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',

    });



});

// function set0(){
//     if (categoryList != null && categoryList != "undefined") {
//         $.each(categoryList, function (i, obj) {
//             $("#noticeType").append("<option value='"+obj.id+"' >"+obj.cateName+"</option>");
//         })
//     }
// }
// function set1(type){
//     if (categoryList != null && categoryList != "undefined") {
//         $.each(categoryList, function (i, obj) {
//             if(type === obj.id){
//                 $("#noticeType").append("<option value='"+obj.id+"' >"+obj.cateName+"</option>");
//             }
//         })
//     }
// }

//操作中的按钮样式
function addNoticeTitle() {
    var noticeTitle = $("#noticeTitle").val();
    var noticeType = type;
    if(null==noticeTitle || noticeTitle == ""){
        $("#noticeTitle").addClass("has-error");
        return false;
    }
    if(null==noticeType || noticeType == ""){
        // $("#noticeType").addClass("has-error");
        return false;
    }
    $.ajax({
        url:application.contextPath+"/notice/addNoticeTitle",
        type:"POST",
        dataType:"json",
        data:{
            "noticeTitle":noticeTitle,
            "noticeType":noticeType
        },
        success:function (res) {
            if(!res.isSuccess){
                layer.open({
                    title:"新增标题失败!",
                    content:res.message
                });
                return ;
            }else{
                $("#noticeId").val(res.data);
                $("#noticeTitle").hide();
                $("#labTitle").html(noticeTitle);
                $("#labTitle").show();
                // $("#noticeTitle").hide();
                $("#saveNameBtn").hide();
                $("input[type='radio'][name='acceptObj']").eq(0).attr("checked",true);
                //$("#editTitleBtn").show();
            }

        }
    });
};

/**
 * 方法描述:新增公告模块
 * SJC 2018-8-27 16:37:39
 *
*/
function addNoticeDetail(){
   var despatcher=$("input[name='acceptObj']:checked").val();
   var memberList=new Array();
   var member="0";
   if("2" == despatcher){
       memberList= JSON.parse(sessionStorage.getItem("memberList"));
   }else{
        memberList.push(member);
    }
    $.ajax({
        url:application.contextPath+"/notice/updateNoticeDetailTiny",
        type:"POST",
        contentType: "application/json; charset=utf-8",
        dataType:"json",
        data:JSON.stringify({
            "memberList":memberList,
            "noticeId":$("#noticeId").val(),
            "contentDetail":tinymce.activeEditor.getContent()
        }),
        success:function (res) {
            if(res.isSuccess && res.data.reCode=="4001"){
                layer.msg('公告新增成功', {
                    icon: 1, title: '新增提示', btn: ['是'], yes() {
                        layer.close(layer.index);
                        loadUtil = new Load($);
                        loadUtil.load({
                            container: '#homeContent',
                            url: application.contextPath + backUrl
                        });
                    }
                });
            }else {
                layer.open({
                    title:"加载失败!",
                    content:'页面加载失败!'
                });
            }
        }
    });
}
